{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 第一章 随机模拟和概率\n",
    "\n",
    "这个世界充满了不确定因素，这也是这个世界这么有趣的原因之一。对于不确定事件，我们在理论上建立了概率论作为分析手段，提出了数理统计作为观察、验证和建模手段。而计算机的出现，使得这些理论和模型，不但可以在现实世界中验证，也可以在虚拟的数字空间中实现、验证和发展。我们这门课，主要目的就是向大家简单介绍一下，目前人类在这方面积累的理论和技术。由于时间关系，我们的介绍将是纲要性的，很多细节不可能展开，而是有待大家在后续课程，或者根据自身的兴趣和选择进行自学。\n",
    "\n",
    "## 一个简单的例子\n",
    "\n",
    "**例 1.1** 客车有 $n$ 个座位，乘客排队上车，对号入座。假定第一个乘客的车票不慎丢失，该乘客任选一个座位坐下。后面的乘客持票上车后，如果自己的座位空着，则坐在自己的座位上，否则也任选一个空座位坐下。请计算，最后一个乘客上车后，刚好坐在自己座位上的概率。（这里没有说明乘客总数，我们就当乘客也是 $n$ 人好了。）\n",
    "\n",
    "这道题作为一道概率论的问题，不能算难。不过我们今天看看这样的问题，如果用计算机模拟来解，是否有难度。我们这里采用的代码是 Python，为省事具体环境直接采用 Anaconda Jupter-Notebook(安装参见 https://mirror.tuna.tsinghua.edu.cn/help/anaconda/ )，大家习惯就好。\n",
    "\n",
    "\n",
    "首先导入随机数生成器，我们这里固定随机数种子，使得我们产生的随机序列每一次都是相同的。其中的具体原理我们以后的章节再讨论。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "import numpy as np\n",
    "np.random.seed(250)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "我们用一个数组来记录各座位的占据情况，第 $i$ 个元素代表第 $i$ 个座位实际上被手持第几号座位票的乘客占据。初始全部赋 $-1$，表示没有被占据："
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [],
   "source": [
    "def init_car_seats(n):\n",
    "    A = np.ones(n, dtype='int32') * -1\n",
    "    return A"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "这里我们不妨设第 $i$ 个上车的乘客，手持的是 $i$ 号座位号，他理当坐在 $i$ 号座位上，但是因为之前出现过不靠谱的乘客，因此他的座位有可能被占据，此时他就加入不靠谱系列，也开始乱坐。（这里的“不妨设”是否合理？）我们将第 $i$ 个乘客上车坐下的过程用一个函数来模拟："
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [],
   "source": [
    "def boarding(i, car_seats):\n",
    "    n = car_seats.size\n",
    "    if i == 0:   # 第一个乘客\n",
    "        s = np.random.randint(0, n)   # 乱坐\n",
    "        car_seats[s] = i;\n",
    "    elif car_seats[i] == -1:   # 第 i 个乘客，他的位置还空着\n",
    "        car_seats[i] = i       # 坐到自己的位置上   \n",
    "    else:                      # 座位被占了\n",
    "        m = np.random.randint(1, n - i + 1)   # 在剩下的位子中随机找一个   \n",
    "        k = 0\n",
    "        for s in range(0, n):                 # 遍历全部座位\n",
    "            if car_seats[s] == -1:            # 对空位计数\n",
    "                k+=1                          \n",
    "            if k == m:                        # 找到第 m 个空位\n",
    "                car_seats[s] = i              # 占据\n",
    "                break\n",
    "    return car_seats"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "这里关键一步是如何模拟“在剩下的空余座位中随机坐一个”。因为座位是有序的线性排列，而我又不想每次刷新当前空余座位列表，所以我这里事实上在最小 $1$ 到最大剩余座位总数 $n - 1$ 之间先取一个随机数 $s$，然后**从头逐个遍历全部座位**，如果每发现一个空座位，我就计数器加一，直到数到第 $s$ 个空座位（必然存在），就占据这个位置。也就是占据第 $s$ 个**空余**的位置。这样做的效率在最坏情况下，是 $\\Theta(n^2)$ 的。如果 $n$ 的规模巨大，那么我们可以通过适当的数据结构来降低这个复杂度。\n",
    "\n",
    "接下去的模拟流程大家以后会经常看见。我先给出一次实验的模拟，也就是给定 $n$ 个座位和 $n$ 个乘客，开始逐一上车，判定最后一个乘客是否坐在自己的位置上。注意计算机模拟的一个倾向是，在不严重影响效率的情况下，模拟过程尽可能贴近实际事件发生过程。尽管不可避免的，如上面的代码，有时确实需要利用概率等价性做一些转换。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [],
   "source": [
    "def one_test(n):\n",
    "    car_seats = init_car_seats(n)\n",
    "    for i in range(0, n):\n",
    "        boarding(i, car_seats)\n",
    "    if car_seats[i] == i:\n",
    "        return True\n",
    "    else:\n",
    "        return False"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "然后是批量实验。计算机模拟不是概率推导，而是实实在在的统计计数。对规模为 $n$ 的问题，我们做 $N$ 次实验，统计其成功次数 $s$，当 $N$ 充分大时，\n",
    "$$\n",
    "s / N \\approx P\\{n\\},\n",
    "$$\n",
    "这个就是大数定律，也是我们计算模拟和一切统计计算的基础。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [],
   "source": [
    "def batch_test(N, n):\n",
    "    success = 0\n",
    "    for i in range(0, N):\n",
    "        if one_test(n):\n",
    "            success += 1\n",
    "    success_rate = success / N        \n",
    "    print(success_rate)\n",
    "    return success_rate"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "我们来给一些计算实例："
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "0.489\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "0.489"
      ]
     },
     "execution_count": 15,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "batch_test(5000, 20)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "从上面的实例，我们严重怀疑，这个事件的发生概率，和 $n$ 无关，而且是常数 $0.5$。这个结论似乎有点违背我们的直观？那么如何来验证这一点？再次强调，以上实验，均不是严格的概率证明，那如何体现其可信度呢？虽然少量的实验结果给我们一些暗示，但那显然是不够的。唯一可行的做法，是做大量的实验，不但让 $N$ 足够大，而且要做充分多组的实验，并且以一定的**统计分析**或**可视化**的方式，将结果的正确性展示出来。也就是我们在物理实验中常用的，控制变量法。比如我们考虑将规模从 $n = 5$ 线性增长到 $n = 500$，然后看一下结果的变化："
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[0, 1, 2, 3, 4]"
      ]
     },
     "execution_count": 22,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "R0=[0,1,2,3,4]\n",
    "R0"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[0, 1, 4, 9, 16]"
      ]
     },
     "execution_count": 24,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "R=[i*i for i in R0]\n",
    "R"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "0.51\n",
      "0.49\n",
      "0.485\n",
      "0.494\n",
      "0.48\n",
      "0.502\n",
      "0.513\n",
      "0.499\n",
      "0.487\n",
      "0.503\n",
      "0.48\n",
      "0.489\n",
      "0.497\n",
      "0.488\n",
      "0.518\n",
      "0.512\n",
      "0.492\n",
      "0.518\n",
      "0.514\n",
      "0.512\n",
      "0.485\n",
      "0.515\n",
      "0.498\n",
      "0.504\n",
      "0.524\n",
      "0.512\n",
      "0.498\n",
      "0.492\n",
      "0.504\n",
      "0.525\n",
      "0.506\n",
      "0.511\n",
      "0.525\n",
      "0.495\n",
      "0.532\n",
      "0.494\n",
      "0.518\n",
      "0.515\n",
      "0.508\n",
      "0.472\n",
      "0.504\n",
      "0.5\n",
      "0.478\n",
      "0.503\n",
      "0.502\n",
      "0.493\n",
      "0.478\n",
      "0.516\n",
      "0.496\n",
      "0.477\n",
      "0.506\n",
      "0.509\n",
      "0.486\n",
      "0.508\n",
      "0.502\n",
      "0.5\n",
      "0.469\n",
      "0.502\n",
      "0.489\n",
      "0.501\n",
      "0.494\n",
      "0.489\n",
      "0.489\n",
      "0.482\n",
      "0.491\n",
      "0.499\n",
      "0.472\n",
      "0.488\n",
      "0.475\n",
      "0.508\n",
      "0.509\n",
      "0.495\n",
      "0.488\n",
      "0.489\n",
      "0.523\n",
      "0.495\n",
      "0.516\n",
      "0.502\n",
      "0.493\n",
      "0.492\n",
      "0.483\n",
      "0.529\n",
      "0.494\n",
      "0.512\n",
      "0.512\n",
      "0.491\n",
      "0.515\n",
      "0.496\n",
      "0.505\n",
      "0.502\n",
      "0.512\n",
      "0.483\n",
      "0.524\n",
      "0.488\n",
      "0.505\n",
      "0.516\n",
      "0.509\n",
      "0.516\n",
      "0.52\n",
      "0.503\n",
      "0.509\n"
     ]
    }
   ],
   "source": [
    "N = 1000   # 重复试验次数\n",
    "T = 100    # 总试验组数\n",
    "C0 = 5     # 试验起始规模\n",
    "cases=np.arange(C0, C0 + T + 1)        # 产生全部试验规模\n",
    "sr=[batch_test(N, i) for i in cases]   # 逐个试验并记录"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "这里注意 `sr` 的生成手段是 Python 的一个特色，可以省略书写一组循环。光看输出似乎是支持我们的结论的，但是最好有个图像更加直观一些。接下去准备图像输出。这里要用到 `matplot` 类库，以后全部用到的类库都会预先在文件初始导入（这里如果不想看到每一次的 `print` 输出，可以在上面的函数定义中注释掉以提高效率，但是看不见输出会焦虑）："
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "metadata": {},
   "outputs": [],
   "source": [
    "import matplotlib.pyplot as plt"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "图像输出参数调整一看就会："
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/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j3bt1Yi4ruAPwe2AQ8Br6Fz8LTpxkVE/CbwY3Q+XXYf8Do615KLHxsR8T5ggc5P+z4O/DrwIWrGQffN74/pfLrmq8BrMvOe1tpiuEtSebwsI0kFMtwlqUCGuyQVyHCXpAIZ7pJUIMNdkgpkuEtSgf4PaYwzw7yo5JEAAAAASUVORK5CYII=\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "plt.plot(np.arange(C0, C0 + T + 1), sr, 'b.')\n",
    "plt.plot([C0, C0 + T + 1], [0.5, 0.5], 'r-')   # 参考线 0.5\n",
    "axs = plt.gca()\n",
    "plt.axis([C0, C0 + T, 0, 1])\n",
    "plt.grid(True)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "这里可以看到，实际结果在 $0.5$ 附近波动，并没有随 $n$ 增长而增长。现在我们有理由猜测，最终结果就是 $0.5$，我们无法仅用计算机证明这一点。但是我们至少可以检验，它是否违背概率论的一般定理，比如大数定律。如果它服从大数定律，那么随着重复试验次数 $N$ 的增长，频率的波动应该收窄："
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "0.1\n",
      "0.6\n",
      "0.5\n",
      "0.65\n",
      "0.54\n",
      "0.5166666666666667\n",
      "0.5285714285714286\n",
      "0.475\n",
      "0.4444444444444444\n",
      "0.49\n",
      "0.42727272727272725\n",
      "0.5166666666666667\n",
      "0.5\n",
      "0.5142857142857142\n",
      "0.5\n",
      "0.475\n",
      "0.4823529411764706\n",
      "0.5166666666666667\n",
      "0.5052631578947369\n",
      "0.53\n",
      "0.47619047619047616\n",
      "0.4954545454545455\n",
      "0.4956521739130435\n",
      "0.48333333333333334\n",
      "0.452\n",
      "0.47307692307692306\n",
      "0.5037037037037037\n",
      "0.48928571428571427\n",
      "0.5206896551724138\n",
      "0.5166666666666667\n",
      "0.4774193548387097\n",
      "0.478125\n",
      "0.5575757575757576\n",
      "0.5735294117647058\n",
      "0.49142857142857144\n",
      "0.49166666666666664\n",
      "0.5054054054054054\n",
      "0.5263157894736842\n",
      "0.46153846153846156\n",
      "0.495\n",
      "0.4902439024390244\n",
      "0.4523809523809524\n",
      "0.5162790697674419\n",
      "0.5022727272727273\n",
      "0.4911111111111111\n",
      "0.4652173913043478\n",
      "0.4957446808510638\n",
      "0.4895833333333333\n",
      "0.46938775510204084\n",
      "0.552\n",
      "0.47058823529411764\n",
      "0.49230769230769234\n",
      "0.5188679245283019\n",
      "0.5407407407407407\n",
      "0.49272727272727274\n",
      "0.4625\n",
      "0.5017543859649123\n",
      "0.5\n",
      "0.5101694915254237\n",
      "0.525\n",
      "0.4901639344262295\n",
      "0.5016129032258064\n",
      "0.5079365079365079\n",
      "0.4953125\n",
      "0.4938461538461538\n",
      "0.5257575757575758\n",
      "0.48955223880597015\n",
      "0.5073529411764706\n",
      "0.4985507246376812\n",
      "0.5085714285714286\n",
      "0.49295774647887325\n",
      "0.4861111111111111\n",
      "0.4958904109589041\n",
      "0.47297297297297297\n",
      "0.5\n",
      "0.5144736842105263\n",
      "0.5116883116883116\n",
      "0.48846153846153845\n",
      "0.5189873417721519\n",
      "0.485\n",
      "0.49382716049382713\n",
      "0.48048780487804876\n",
      "0.5072289156626506\n",
      "0.4880952380952381\n",
      "0.5047058823529412\n",
      "0.4930232558139535\n",
      "0.4908045977011494\n",
      "0.5034090909090909\n",
      "0.5235955056179775\n",
      "0.49666666666666665\n",
      "0.5021978021978022\n",
      "0.5097826086956522\n",
      "0.4978494623655914\n",
      "0.5\n",
      "0.48947368421052634\n",
      "0.534375\n",
      "0.5020618556701031\n",
      "0.5010204081632653\n",
      "0.5404040404040404\n",
      "0.516\n",
      "0.5396039603960396\n",
      "0.5245098039215687\n",
      "0.48349514563106794\n",
      "0.4951923076923077\n",
      "0.5123809523809524\n",
      "0.5160377358490567\n",
      "0.5018691588785047\n",
      "0.5120370370370371\n",
      "0.5064220183486239\n",
      "0.4818181818181818\n",
      "0.4846846846846847\n",
      "0.48392857142857143\n",
      "0.5212389380530974\n",
      "0.5078947368421053\n",
      "0.48869565217391303\n",
      "0.49051724137931035\n",
      "0.47692307692307695\n",
      "0.5\n",
      "0.5033613445378151\n",
      "0.5091666666666667\n",
      "0.49504132231404957\n",
      "0.4934426229508197\n",
      "0.5065040650406504\n",
      "0.5016129032258064\n",
      "0.5232\n",
      "0.5126984126984127\n",
      "0.5062992125984253\n",
      "0.51875\n",
      "0.513953488372093\n",
      "0.5053846153846154\n",
      "0.5106870229007634\n",
      "0.5007575757575757\n",
      "0.5105263157894737\n",
      "0.5082089552238805\n",
      "0.4955555555555556\n",
      "0.49779411764705883\n",
      "0.5109489051094891\n",
      "0.5202898550724637\n",
      "0.497841726618705\n",
      "0.5071428571428571\n",
      "0.49432624113475176\n",
      "0.5105633802816901\n",
      "0.5006993006993007\n",
      "0.5194444444444445\n",
      "0.5055172413793103\n",
      "0.5054794520547945\n",
      "0.5027210884353741\n",
      "0.4972972972972973\n",
      "0.4986577181208054\n",
      "0.49333333333333335\n",
      "0.5119205298013245\n",
      "0.48092105263157897\n",
      "0.4849673202614379\n",
      "0.5077922077922078\n",
      "0.4670967741935484\n",
      "0.5185897435897436\n",
      "0.4821656050955414\n",
      "0.4911392405063291\n",
      "0.5169811320754717\n",
      "0.513125\n",
      "0.5118012422360249\n",
      "0.5049382716049383\n",
      "0.5006134969325153\n",
      "0.49390243902439024\n",
      "0.5072727272727273\n",
      "0.4951807228915663\n",
      "0.492814371257485\n",
      "0.48988095238095236\n",
      "0.493491124260355\n",
      "0.5064705882352941\n",
      "0.49064327485380116\n",
      "0.4790697674418605\n",
      "0.47861271676300576\n",
      "0.4827586206896552\n",
      "0.5097142857142857\n",
      "0.48977272727272725\n",
      "0.4858757062146893\n",
      "0.48820224719101124\n",
      "0.49329608938547487\n",
      "0.5011111111111111\n",
      "0.5027624309392266\n",
      "0.49615384615384617\n",
      "0.4885245901639344\n",
      "0.48206521739130437\n",
      "0.49891891891891893\n",
      "0.4978494623655914\n",
      "0.5032085561497326\n",
      "0.4824468085106383\n",
      "0.5111111111111111\n",
      "0.5105263157894737\n",
      "0.4968586387434555\n",
      "0.48802083333333335\n",
      "0.47461139896373056\n",
      "0.520618556701031\n",
      "0.4948717948717949\n",
      "0.5071428571428571\n",
      "0.49289340101522844\n",
      "0.5060606060606061\n",
      "0.48894472361809044\n"
     ]
    },
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAXcAAAD8CAYAAACMwORRAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uIDIuMi4zLCBodHRwOi8vbWF0cGxvdGxpYi5vcmcvIxREBQAAHuJJREFUeJzt3X+QHOV95/H3d1a7C/FKCEQiZBCWiOTLqc7nIG0BW74kUsHJgjp+3EFScD4gFlilVFR3LifkUJHiKO4Kl53yhUrgYnAiG1LEMvlhn+oKH3Y47cVVWmyQLbAFQSxYJgIJbEASgkOytN/7o7s1Pb09Mz27Pb8efV5VI+30PNP97ae7v/30M8/0mLsjIiJhqXQ7ABERKZ+Su4hIgJTcRUQCpOQuIhIgJXcRkQApuYuIBKhpcjezLWb2hpn9qM7rZmZ/YmaTZvasma0sP0wREWlFkZb7V4B1DV6/HFgePzYAfzb7sEREZDaaJnd3/wfgrQZFrgYe9siTwHwzW1RWgCIi0ro5JczjXOCfUs/3xdP2Zwua2Qai1j2nn376qsWLF5ew+PaZmpqiUun9jyUUZ7n6JU7on1gVZ3n27NnzM3f/xWblykjuljMt954G7v4g8CDA6OioP/300yUsvn3Gx8dZvXp1t8NoSnGWq1/ihP6JVXGWx8x+UqRcGaeofUC6CX4e8FoJ8xURkRkqI7lvA26KR81cAhxy92ldMiIi0jlNu2XM7KvAauBsM9sH/BdgEMDdvwg8BlwBTALvAZ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fjMteG+8TzwDfB65MzWeUKLG+BNxH/G30DsTa8raOj7s98Wt3dCLOePpXgI2Zsl2t0zIfuv2AiEiATtluGRGRkCm5i4gESMldRCRASu4iIgFSchcRCZCSu4hIgJTcRUQC9P8BrcUVVyKGKMUAAAAASUVORK5CYII=\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "N = np.arange(10, 2000, 10)\n",
    "n = 10\n",
    "sr=[batch_test(i, n) for i in N]\n",
    "plt.plot(N, sr, 'b.')\n",
    "plt.plot([10, 1990], [0.5, 0.5], 'r-')   # 参考线 0.5\n",
    "axs = plt.gca()\n",
    "plt.axis([10, 1990, 0, 1])\n",
    "plt.grid(True)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "我们看到确实有这种现象。更进一步，我们甚至可以直接绘制出 `sr` 的分布情况，这里我们问题规模取 $n$，每组试验重复次数为 $N$，总共做 $T$ 组："
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "0.46\n",
      "0.512\n",
      "0.52\n",
      "0.508\n",
      "0.512\n",
      "0.466\n",
      "0.518\n",
      "0.472\n",
      "0.512\n",
      "0.506\n",
      "0.496\n",
      "0.474\n",
      "0.526\n",
      "0.5\n",
      "0.472\n",
      "0.506\n",
      "0.53\n",
      "0.488\n",
      "0.53\n",
      "0.5\n",
      "0.476\n",
      "0.476\n",
      "0.506\n",
      "0.54\n",
      "0.496\n",
      "0.516\n",
      "0.442\n",
      "0.488\n",
      "0.508\n",
      "0.494\n",
      "0.49\n",
      "0.5\n",
      "0.504\n",
      "0.472\n",
      "0.486\n",
      "0.512\n",
      "0.536\n",
      "0.514\n",
      "0.464\n",
      "0.514\n",
      "0.464\n",
      "0.45\n",
      "0.494\n",
      "0.488\n",
      "0.5\n",
      "0.468\n",
      "0.494\n",
      "0.522\n",
      "0.504\n",
      "0.52\n",
      "0.488\n",
      "0.472\n",
      "0.482\n",
      "0.486\n",
      "0.484\n",
      "0.47\n",
      "0.484\n",
      "0.454\n",
      "0.496\n",
      "0.496\n",
      "0.49\n",
      "0.474\n",
      "0.52\n",
      "0.452\n",
      "0.508\n",
      "0.496\n",
      "0.504\n",
      "0.504\n",
      "0.48\n",
      "0.51\n",
      "0.452\n",
      "0.488\n",
      "0.492\n",
      "0.582\n",
      "0.49\n",
      "0.52\n",
      "0.518\n",
      "0.526\n",
      "0.498\n",
      "0.534\n",
      "0.456\n",
      "0.532\n",
      "0.522\n",
      "0.522\n",
      "0.488\n",
      "0.478\n",
      "0.508\n",
      "0.484\n",
      "0.528\n",
      "0.502\n",
      "0.506\n",
      "0.52\n",
      "0.48\n",
      "0.472\n",
      "0.48\n",
      "0.488\n",
      "0.554\n",
      "0.536\n",
      "0.512\n",
      "0.534\n",
      "0.534\n",
      "0.476\n",
      "0.506\n",
      "0.53\n",
      "0.508\n",
      "0.552\n",
      "0.538\n",
      "0.458\n",
      "0.526\n",
      "0.55\n",
      "0.502\n",
      "0.48\n",
      "0.566\n",
      "0.516\n",
      "0.536\n",
      "0.45\n",
      "0.492\n",
      "0.512\n",
      "0.46\n",
      "0.516\n",
      "0.51\n",
      "0.492\n",
      "0.462\n",
      "0.536\n",
      "0.522\n",
      "0.542\n",
      "0.55\n",
      "0.488\n",
      "0.502\n",
      "0.502\n",
      "0.492\n",
      "0.488\n",
      "0.502\n",
      "0.498\n",
      "0.514\n",
      "0.488\n",
      "0.474\n",
      "0.524\n",
      "0.488\n",
      "0.508\n",
      "0.508\n",
      "0.464\n",
      "0.53\n",
      "0.516\n",
      "0.464\n",
      "0.48\n",
      "0.514\n",
      "0.508\n",
      "0.492\n",
      "0.51\n",
      "0.528\n",
      "0.518\n",
      "0.492\n",
      "0.506\n",
      "0.474\n",
      "0.466\n",
      "0.526\n",
      "0.494\n",
      "0.498\n",
      "0.492\n",
      "0.47\n",
      "0.466\n",
      "0.5\n",
      "0.538\n",
      "0.504\n",
      "0.534\n",
      "0.466\n",
      "0.488\n",
      "0.502\n",
      "0.508\n",
      "0.448\n",
      "0.544\n",
      "0.502\n",
      "0.492\n",
      "0.464\n",
      "0.562\n",
      "0.468\n",
      "0.498\n",
      "0.486\n",
      "0.482\n",
      "0.466\n",
      "0.492\n",
      "0.482\n",
      "0.484\n",
      "0.496\n",
      "0.494\n",
      "0.518\n",
      "0.496\n",
      "0.532\n",
      "0.486\n",
      "0.492\n",
      "0.442\n",
      "0.502\n",
      "0.556\n",
      "0.502\n",
      "0.452\n",
      "0.472\n",
      "0.494\n",
      "0.484\n",
      "0.504\n",
      "0.518\n",
      "0.494\n",
      "0.462\n",
      "0.486\n",
      "0.464\n",
      "0.508\n",
      "0.526\n",
      "0.442\n",
      "0.456\n",
      "0.512\n",
      "0.488\n",
      "0.512\n",
      "0.48\n",
      "0.49\n",
      "0.494\n",
      "0.506\n",
      "0.524\n",
      "0.468\n",
      "0.536\n",
      "0.498\n",
      "0.522\n",
      "0.474\n",
      "0.506\n",
      "0.458\n",
      "0.496\n",
      "0.47\n",
      "0.51\n",
      "0.55\n",
      "0.492\n",
      "0.486\n",
      "0.516\n",
      "0.482\n",
      "0.496\n",
      "0.498\n",
      "0.494\n",
      "0.508\n",
      "0.512\n",
      "0.508\n",
      "0.51\n",
      "0.484\n",
      "0.48\n",
      "0.49\n",
      "0.52\n",
      "0.48\n",
      "0.472\n",
      "0.462\n",
      "0.45\n",
      "0.5\n",
      "0.49\n",
      "0.506\n",
      "0.488\n",
      "0.506\n",
      "0.496\n",
      "0.494\n",
      "0.492\n",
      "0.522\n",
      "0.542\n",
      "0.494\n",
      "0.496\n",
      "0.482\n",
      "0.504\n",
      "0.484\n",
      "0.466\n",
      "0.508\n",
      "0.468\n",
      "0.492\n",
      "0.518\n",
      "0.478\n",
      "0.538\n",
      "0.472\n",
      "0.528\n",
      "0.53\n",
      "0.538\n",
      "0.49\n",
      "0.49\n",
      "0.492\n",
      "0.48\n",
      "0.47\n",
      "0.46\n",
      "0.52\n",
      "0.512\n",
      "0.512\n",
      "0.452\n",
      "0.502\n",
      "0.504\n",
      "0.53\n",
      "0.458\n",
      "0.482\n",
      "0.528\n",
      "0.488\n",
      "0.518\n",
      "0.522\n",
      "0.5\n",
      "0.472\n",
      "0.494\n",
      "0.502\n",
      "0.512\n",
      "0.486\n",
      "0.508\n",
      "0.478\n",
      "0.5\n",
      "0.492\n",
      "0.5\n",
      "0.496\n",
      "0.538\n",
      "0.522\n",
      "0.492\n",
      "0.484\n",
      "0.524\n",
      "0.514\n",
      "0.48\n",
      "0.506\n",
      "0.512\n",
      "0.5\n",
      "0.468\n",
      "0.494\n",
      "0.486\n",
      "0.484\n",
      "0.468\n",
      "0.512\n",
      "0.474\n",
      "0.484\n",
      "0.566\n",
      "0.512\n",
      "0.534\n",
      "0.514\n",
      "0.534\n",
      "0.478\n",
      "0.502\n",
      "0.482\n",
      "0.54\n",
      "0.48\n",
      "0.458\n",
      "0.472\n",
      "0.512\n",
      "0.434\n",
      "0.514\n",
      "0.546\n",
      "0.494\n",
      "0.472\n",
      "0.494\n",
      "0.514\n",
      "0.522\n",
      "0.486\n",
      "0.534\n",
      "0.514\n",
      "0.508\n",
      "0.45\n",
      "0.488\n",
      "0.498\n",
      "0.466\n",
      "0.478\n",
      "0.494\n",
      "0.51\n",
      "0.532\n",
      "0.482\n",
      "0.53\n",
      "0.488\n",
      "0.478\n",
      "0.518\n",
      "0.492\n",
      "0.448\n",
      "0.486\n",
      "0.492\n",
      "0.48\n",
      "0.462\n",
      "0.494\n",
      "0.478\n",
      "0.506\n",
      "0.474\n",
      "0.506\n",
      "0.494\n",
      "0.494\n",
      "0.486\n",
      "0.502\n",
      "0.422\n",
      "0.508\n",
      "0.508\n",
      "0.472\n",
      "0.508\n",
      "0.504\n",
      "0.458\n",
      "0.508\n",
      "0.52\n",
      "0.52\n",
      "0.502\n",
      "0.522\n",
      "0.478\n",
      "0.5\n",
      "0.482\n",
      "0.516\n",
      "0.472\n",
      "0.49\n",
      "0.546\n",
      "0.544\n",
      "0.522\n",
      "0.542\n",
      "0.548\n",
      "0.45\n",
      "0.52\n",
      "0.466\n",
      "0.522\n",
      "0.492\n",
      "0.546\n",
      "0.512\n",
      "0.492\n",
      "0.486\n",
      "0.528\n",
      "0.516\n",
      "0.504\n",
      "0.49\n",
      "0.476\n",
      "0.524\n",
      "0.51\n",
      "0.51\n",
      "0.448\n",
      "0.532\n",
      "0.526\n",
      "0.5\n",
      "0.502\n",
      "0.52\n",
      "0.502\n",
      "0.5\n",
      "0.492\n",
      "0.484\n",
      "0.514\n",
      "0.53\n",
      "0.51\n",
      "0.546\n",
      "0.496\n",
      "0.496\n",
      "0.484\n",
      "0.5\n",
      "0.534\n",
      "0.52\n",
      "0.466\n",
      "0.51\n",
      "0.478\n",
      "0.474\n",
      "0.522\n",
      "0.506\n",
      "0.488\n",
      "0.536\n",
      "0.522\n",
      "0.512\n",
      "0.534\n",
      "0.502\n",
      "0.508\n",
      "0.526\n",
      "0.528\n",
      "0.488\n",
      "0.494\n",
      "0.522\n",
      "0.512\n",
      "0.5\n",
      "0.55\n",
      "0.488\n",
      "0.49\n",
      "0.47\n",
      "0.498\n",
      "0.532\n",
      "0.488\n",
      "0.514\n",
      "0.444\n",
      "0.51\n",
      "0.472\n",
      "0.518\n",
      "0.476\n",
      "0.51\n",
      "0.51\n",
      "0.472\n",
      "0.498\n",
      "0.492\n",
      "0.524\n",
      "0.51\n",
      "0.482\n",
      "0.496\n",
      "0.48\n",
      "0.496\n",
      "0.518\n",
      "0.516\n",
      "0.498\n",
      "0.496\n",
      "0.464\n",
      "0.52\n",
      "0.506\n",
      "0.53\n",
      "0.516\n",
      "0.466\n",
      "0.506\n",
      "0.494\n",
      "0.54\n",
      "0.464\n",
      "0.542\n",
      "0.492\n",
      "0.516\n",
      "0.508\n",
      "0.516\n",
      "0.488\n",
      "0.514\n",
      "0.51\n",
      "0.488\n",
      "0.49\n",
      "0.47\n",
      "0.462\n",
      "0.488\n",
      "0.474\n",
      "0.52\n",
      "0.496\n",
      "0.476\n",
      "0.508\n",
      "0.524\n",
      "0.504\n",
      "0.486\n",
      "0.484\n",
      "0.512\n",
      "0.52\n",
      "0.492\n",
      "0.504\n",
      "0.512\n",
      "0.514\n",
      "0.516\n",
      "0.478\n",
      "0.492\n",
      "0.48\n",
      "0.472\n",
      "0.474\n",
      "0.532\n",
      "0.502\n",
      "0.488\n",
      "0.51\n",
      "0.482\n",
      "0.554\n",
      "0.486\n",
      "0.492\n",
      "0.468\n",
      "0.52\n",
      "0.49\n",
      "0.496\n",
      "0.494\n",
      "0.528\n",
      "0.494\n",
      "0.488\n",
      "0.476\n",
      "0.488\n",
      "0.544\n",
      "0.49\n",
      "0.496\n",
      "0.502\n",
      "0.49\n",
      "0.434\n",
      "0.48\n",
      "0.524\n",
      "0.508\n",
      "0.48\n",
      "0.49\n",
      "0.516\n",
      "0.514\n",
      "0.532\n",
      "0.504\n",
      "0.48\n",
      "0.464\n",
      "0.478\n",
      "0.474\n",
      "0.498\n",
      "0.498\n",
      "0.536\n",
      "0.472\n",
      "0.488\n",
      "0.512\n",
      "0.502\n",
      "0.488\n",
      "0.476\n",
      "0.494\n",
      "0.49\n",
      "0.508\n",
      "0.52\n",
      "0.498\n",
      "0.532\n",
      "0.49\n",
      "0.484\n",
      "0.528\n",
      "0.508\n",
      "0.512\n",
      "0.5\n",
      "0.504\n",
      "0.456\n",
      "0.492\n",
      "0.526\n",
      "0.5\n",
      "0.518\n",
      "0.456\n",
      "0.536\n",
      "0.514\n",
      "0.522\n",
      "0.496\n",
      "0.502\n",
      "0.518\n",
      "0.5\n",
      "0.486\n",
      "0.506\n",
      "0.512\n",
      "0.52\n",
      "0.492\n",
      "0.498\n",
      "0.52\n",
      "0.512\n",
      "0.512\n",
      "0.488\n",
      "0.514\n",
      "0.484\n",
      "0.498\n",
      "0.53\n",
      "0.488\n",
      "0.482\n",
      "0.48\n",
      "0.512\n",
      "0.554\n",
      "0.488\n",
      "0.554\n",
      "0.494\n",
      "0.524\n",
      "0.47\n",
      "0.488\n",
      "0.506\n",
      "0.452\n",
      "0.536\n",
      "0.484\n",
      "0.51\n",
      "0.472\n",
      "0.554\n",
      "0.478\n",
      "0.508\n",
      "0.516\n",
      "0.468\n",
      "0.51\n",
      "0.462\n",
      "0.496\n",
      "0.498\n",
      "0.492\n",
      "0.466\n",
      "0.534\n",
      "0.484\n",
      "0.504\n",
      "0.526\n",
      "0.498\n",
      "0.512\n",
      "0.498\n",
      "0.468\n",
      "0.52\n",
      "0.466\n",
      "0.46\n",
      "0.51\n",
      "0.512\n",
      "0.5\n",
      "0.526\n",
      "0.496\n",
      "0.562\n",
      "0.536\n",
      "0.456\n",
      "0.492\n",
      "0.516\n",
      "0.492\n",
      "0.492\n",
      "0.566\n",
      "0.492\n",
      "0.528\n",
      "0.498\n",
      "0.478\n",
      "0.498\n",
      "0.48\n",
      "0.51\n",
      "0.534\n",
      "0.464\n",
      "0.476\n",
      "0.542\n",
      "0.528\n",
      "0.484\n",
      "0.494\n",
      "0.496\n",
      "0.486\n",
      "0.494\n",
      "0.488\n",
      "0.506\n",
      "0.492\n",
      "0.51\n",
      "0.506\n",
      "0.476\n",
      "0.51\n",
      "0.528\n",
      "0.474\n",
      "0.484\n",
      "0.492\n",
      "0.508\n",
      "0.53\n",
      "0.496\n",
      "0.542\n",
      "0.472\n",
      "0.476\n",
      "0.516\n",
      "0.49\n",
      "0.524\n",
      "0.5\n",
      "0.514\n",
      "0.498\n",
      "0.528\n",
      "0.522\n",
      "0.502\n",
      "0.47\n",
      "0.494\n",
      "0.51\n",
      "0.492\n",
      "0.522\n",
      "0.51\n",
      "0.476\n",
      "0.438\n",
      "0.504\n",
      "0.492\n",
      "0.49\n",
      "0.498\n",
      "0.462\n",
      "0.502\n",
      "0.492\n",
      "0.498\n",
      "0.512\n",
      "0.512\n",
      "0.494\n",
      "0.468\n",
      "0.474\n",
      "0.494\n",
      "0.506\n",
      "0.506\n",
      "0.464\n",
      "0.478\n",
      "0.506\n",
      "0.508\n",
      "0.51\n",
      "0.436\n",
      "0.506\n",
      "0.48\n",
      "0.478\n",
      "0.468\n",
      "0.47\n",
      "0.506\n",
      "0.482\n",
      "0.506\n",
      "0.472\n",
      "0.476\n",
      "0.49\n",
      "0.516\n",
      "0.53\n",
      "0.51\n",
      "0.49\n",
      "0.526\n",
      "0.496\n",
      "0.494\n",
      "0.51\n",
      "0.536\n",
      "0.488\n",
      "0.508\n",
      "0.512\n",
      "0.488\n",
      "0.506\n",
      "0.496\n",
      "0.504\n",
      "0.462\n",
      "0.47\n",
      "0.524\n",
      "0.466\n",
      "0.478\n",
      "0.464\n",
      "0.472\n",
      "0.484\n",
      "0.49\n",
      "0.532\n",
      "0.504\n",
      "0.476\n",
      "0.504\n",
      "0.454\n",
      "0.49\n",
      "0.488\n",
      "0.5\n",
      "0.508\n",
      "0.488\n",
      "0.452\n",
      "0.454\n",
      "0.47\n",
      "0.498\n",
      "0.466\n",
      "0.488\n",
      "0.486\n",
      "0.488\n",
      "0.47\n",
      "0.47\n",
      "0.496\n",
      "0.476\n",
      "0.522\n",
      "0.524\n",
      "0.492\n",
      "0.538\n",
      "0.536\n",
      "0.474\n",
      "0.514\n",
      "0.466\n",
      "0.506\n",
      "0.51\n",
      "0.496\n",
      "0.546\n",
      "0.46\n",
      "0.5\n",
      "0.518\n",
      "0.508\n",
      "0.56\n",
      "0.524\n",
      "0.47\n",
      "0.516\n",
      "0.482\n",
      "0.508\n",
      "0.502\n",
      "0.468\n",
      "0.532\n",
      "0.474\n",
      "0.492\n",
      "0.494\n",
      "0.498\n",
      "0.518\n",
      "0.498\n",
      "0.506\n",
      "0.466\n",
      "0.488\n",
      "0.48\n",
      "0.478\n",
      "0.512\n",
      "0.502\n",
      "0.484\n",
      "0.488\n",
      "0.478\n",
      "0.486\n",
      "0.5\n",
      "0.48\n",
      "0.534\n",
      "0.508\n",
      "0.516\n",
      "0.54\n",
      "0.52\n",
      "0.494\n",
      "0.472\n",
      "0.476\n",
      "0.502\n",
      "0.516\n",
      "0.492\n",
      "0.514\n",
      "0.514\n",
      "0.5\n",
      "0.496\n",
      "0.494\n",
      "0.522\n",
      "0.506\n",
      "0.476\n",
      "0.494\n",
      "0.536\n",
      "0.516\n",
      "0.516\n",
      "0.52\n",
      "0.524\n",
      "0.482\n",
      "0.518\n",
      "0.49\n",
      "0.494\n",
      "0.474\n",
      "0.47\n",
      "0.482\n",
      "0.524\n",
      "0.478\n",
      "0.554\n",
      "0.49\n",
      "0.476\n",
      "0.488\n",
      "0.498\n",
      "0.52\n",
      "0.426\n",
      "0.514\n",
      "0.506\n",
      "0.49\n",
      "0.468\n",
      "0.472\n",
      "0.502\n",
      "0.544\n",
      "0.488\n",
      "0.476\n",
      "0.518\n",
      "0.532\n",
      "0.532\n",
      "0.502\n",
      "0.524\n",
      "0.486\n",
      "0.456\n",
      "0.498\n",
      "0.506\n",
      "0.542\n",
      "0.496\n",
      "0.472\n",
      "0.482\n",
      "0.524\n",
      "0.484\n",
      "0.51\n",
      "0.446\n",
      "0.486\n",
      "0.506\n",
      "0.464\n",
      "0.49\n",
      "0.512\n",
      "0.464\n",
      "0.484\n",
      "0.52\n",
      "0.546\n",
      "0.51\n",
      "0.502\n",
      "0.466\n",
      "0.508\n",
      "0.518\n",
      "0.514\n",
      "0.504\n",
      "0.512\n",
      "0.47\n",
      "0.514\n",
      "0.474\n",
      "0.52\n",
      "0.536\n",
      "0.542\n",
      "0.5\n",
      "0.494\n",
      "0.442\n",
      "0.5\n",
      "0.534\n",
      "0.476\n",
      "0.516\n",
      "0.506\n",
      "0.504\n",
      "0.478\n",
      "0.492\n",
      "0.536\n",
      "0.516\n",
      "0.452\n",
      "0.5\n",
      "0.506\n",
      "0.486\n",
      "0.54\n",
      "0.478\n",
      "0.532\n",
      "0.52\n",
      "0.512\n",
      "0.46\n",
      "0.492\n",
      "0.508\n",
      "0.468\n",
      "0.46\n",
      "0.484\n",
      "0.522\n",
      "0.488\n",
      "0.512\n",
      "0.508\n",
      "0.484\n",
      "0.496\n",
      "0.504\n",
      "0.526\n",
      "0.508\n",
      "0.49\n",
      "0.482\n",
      "0.516\n",
      "0.508\n",
      "0.554\n",
      "0.474\n",
      "0.49\n",
      "0.502\n",
      "0.498\n",
      "0.512\n",
      "0.532\n",
      "0.506\n",
      "0.48\n",
      "0.472\n",
      "0.464\n",
      "0.518\n",
      "0.514\n",
      "0.524\n",
      "0.486\n",
      "0.476\n",
      "0.506\n",
      "0.48\n",
      "0.504\n",
      "0.518\n",
      "0.484\n",
      "0.49\n",
      "0.494\n",
      "0.498\n",
      "0.504\n",
      "0.496\n",
      "0.48\n",
      "0.502\n",
      "0.494\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "(array([  2.,   4.,  14.,  28.,  70., 110., 142., 172., 160., 132.,  74.,\n",
       "         53.,  23.,  10.,   5.,   1.]),\n",
       " array([0.422, 0.432, 0.442, 0.452, 0.462, 0.472, 0.482, 0.492, 0.502,\n",
       "        0.512, 0.522, 0.532, 0.542, 0.552, 0.562, 0.572, 0.582]),\n",
       " <a list of 16 Patch objects>)"
      ]
     },
     "execution_count": 29,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAXoAAAD8CAYAAAB5Pm/hAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uIDIuMi4zLCBodHRwOi8vbWF0cGxvdGxpYi5vcmcvIxREBQAAEXRJREFUeJzt3W2QZGV9hvHrdlcwIhYgo0FgM2DQRC1ddYImBotIUJREJEYFjYIaVyvywYoa8aUimrKCCFJaJpq1RDCl+IYoEXwhVJRKShIXwRXEF8BVVrbYEYxKNCr4z4c+G9p1dmd2zumZ2YfrV9XVp58+5/RdPT33nn36dE+qCklSu+6x3AEkS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N7sXM3oyOLYFZLt1cD7GB0d7QV8DXjEUmQCDhhb3vaLB6M3Yb/dPW/7dsv7LdVztZNcewCXAS8f+nXfN9t265zMsG/G9nnOVnXrT3W33we8bAXkenb3e7ia0fz8ZcCfDvacTeIF0uOJeirwTUbzjK/rxt4EPG2OdcfL4fWM5nWvHrvcf7lzbTd+GgMWfd9cwF8weoP4GuCMFfSzvA+jM5SuZVTyr1qqTMDfd4/7FUbzpb8ztu0Lgeu7ywuW8rnaUa7uZ/iL7V73a1dCtu32cTIDFv0AP8ujGZ119lXgXGCP5c7F6B+gfwKu6173bxvy+fKTsZLUuJU0Ry9JmgCLXpIaZ9FLUuMseklqnEUvSY2z6CWpcRa9JDXOopekxv0ffeGyJ31TjrgAAAAASUVORK5CYII=\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "N = 500\n",
    "n = 5\n",
    "T = np.arange(1000)\n",
    "sr=[batch_test(N, n) for i in T]\n",
    "plt.hist(sr, bins = 16)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "如果人品够好，这应该是一个正态分布。我们现在可以进行更多的模拟，从而确信 $P_n = 0.5$ 这个结论是对的。当然这不是一个能让张胖子满意的证明，但是在很多实际问题中，我们已经可以得到我们的结论。同时，实验足够多次后得到的结论，本身就是应用统计学存在的依据。\n",
    "\n",
    "**总结：**\n",
    "1. 计算机模拟并不是概率论的证明，它无法给出确信无疑的结论，但是对大多数实际问题，特别是复杂到概率论推理成为巨大挑战的问题，它像物理学实验那样，提供了指示和验证；\n",
    "2. 概率论和数理统计，是计算机模拟的建模和分析基础。没有扎实的概率与数理统计基础，将很难在实际工作中正确并灵活地运用计算机模拟技术；\n",
    "3. 对计算机模拟结果的解释和分析，具有主观性。我们一方面要充分运用统计学的理论和工具进行仔细分析和验证，至少在一些基本事实上不能和概率论有违背；另一方面，适当的可视化能极大提高数据的实际使用意义。\n",
    "\n",
    "## 概率对直观的违背\n",
    "很多现代数学理论，由于其思想的高度抽象和升华，与我们的日常直观是不一致的。大家可能已经开始淡忘极限理论带来的不适感，那是因为进过长期的训练，我们可以改进我们思维模式，从而提升自己的思维的强度和深度。这也是数学改进智商的本质原因之一。在众多数学分支中，概率论对直观的违背是最严重的一个。而通过计算机模拟，有助于我们认识我们自己思维的局限，减轻概率论学习在理解上的困难。或者，这也预示着有这种可能性，对于没有掌握高深概率论知识的人，有可能在具备的基础概率理论水平之后，通过计算机模拟提升自己对随机问题的实际分析能力。这也是我在之前暗示，当我们做计算机模拟时，尽可能少代入自己对模型的概率论理解（因为那可能是错的！），而尽可能照搬现实世界中事件的实际发生过程。\n",
    "\n",
    "这里我们列举一些可能造成概率论和直观违背的例子：\n",
    "1. 书上1.2.1提到的 Monty Hall Problem. 这个例子在电影决胜21点中也出现过；\n",
    "2. 如果没有计划生育政策，且每一个家庭都执行必须有男孩的策略，也就是不断地生，直到出现男孩为止。可以想象，或正如你可能在生活中遇到的那样，会出现7，8个姐妹加一个弟弟的家庭组合。请问在这种情况下，长期以往是否会出现男女性别比例失衡？如果在这样一种落后的社会观念体系中，允许对胎儿进行性别检测，并允许无理由堕胎，请问是否会引起男女性别比例失衡？\n",
    "3. 为什么你不可能中彩票？\n",
    "\n",
    "以上问题，既可以用概率论证明，也可以用计算机模拟验证。对于没有受过足够训练的人，会倾向于更接受后者的结果。万幸，在没有错误的情况下，二者的结论总是一致的。\n",
    "\n",
    "## 动态模拟\n",
    "在很多实际场合，我们关心的一个事件是不停动态变化的。比如各种金融指标，比如战争态势，等等。这些复杂的动态问题的理论模型，往往要涉及概率微分方程等艰深的理论，而近似计算模型的偏差往往也很大。但计算机模拟，在投入足够多计算资源的前提下，却有可能给出非常接近实际情况的结果。至少能提高算力充足方在综合博弈中的胜率。我们会在一些专题分析中纲要性地介绍它们的理论的应用前沿。\n",
    "\n",
    "## 准备工作\n",
    "很明显，我们需要以下的学习准备：\n",
    "1. 概率论基础，对于没有学习过概率论的同学，建议仔细阅读本书第二章；\n",
    "2. 计算机编程基础。我们采用 Python 语言来实现我们的全部模拟。Python语言本身非常接近伪代码和自然语言。我们会在整个授课过程中不断掌握。学习一门语言的唯一途径是去使用它；"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.2"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
